import java.util.Scanner;
public class P5728 {
    public static void main(String args[]){
        int students_count;
        Scanner sc = new Scanner(System.in);
        students_count = sc.nextInt();
        int arr[][] = new int[students_count][4];
        for (int i  = 0 ; i <  students_count; i++){
            arr[i][0] = sc.nextInt();
            arr[i][1] = sc.nextInt();
            arr[i][2] = sc.nextInt();
            arr[i][3] = arr[i][0] + arr[i][1] + arr[i][2];
        }
        int count = 0;
        int score_check_flag = 0;
        for (int i = 0; i < students_count; i++){
            score_check_flag = 0;
            for (int j  = i + 1; j < students_count; j++){
                score_check_flag = 0;

                for (int z = 0 ; z< 3; z++){
                    if (arr[i][z] - arr[j][z] <= 5 && arr[i][z] - arr[j][z] >= -5){
                        score_check_flag++;
                    }
                    else{
                        score_check_flag = 0;
                        break;
                    }
                }

                if (score_check_flag == 3){
                    int sum_score_duration = arr[i][3] - arr[j][3];
                    if (arr[i][3] - arr[j][3] <= 10 && arr[i][3] - arr[j][3] >= -10){
                        count++;
                    }

                }

            }
        }
        System.out.println(count);
    }
}
